创建 Red Envelope 对象

发起一次红包请求需要创建一个新的 red_envelope 对象。如果支付失败,请检查错误信息,一般是由于账户余额不足引起的。使用测试模式的 API Key,则不会发生真实交易,且需要主动调用下方的红包查询接口才能刷新红包订单的状态且触发 Webhooks 回调。同步返回交易结果,不会发送 Webhooks 通知。

请求参数描述
app[id] expandable required string红包使用的 app 对象的 idexpandable 可展开,查看如何获取App ID
channel required string红包使用的第三方支付渠道。目前仅支持wx_pub
order_no required string红包使用的商户订单号。wx_pub 渠道规定为 1 ~ 28 位不能重复的数字。
amount required int红包金额。单位为对应币种的最小货币单位,例如:人民币为分。微信红包常规限额在 100 ~ 20000 之间, 即 1~200 元。如有需要,可前往微信商户平台进行设置和申请红包限额调整。
currency required string三位 ISO 货币代码,目前仅支持人民币 cny
recipient required string接收者 id, 为用户在 wx_pub 下的 open_id。点此参考如何获取open_id
subject required string红包主题名称,最多 32 个字节。
body required string红包祝福语,最多 128 个字节。
description required string备注信息,最多 255 个字节。
extra required hash支付渠道相关的附加参数,具体参考下表 extra 参数说明。
metadata optional hash参考元数据
extra 参数描述
send_name required string商户名称,最多 32 个字节。
scene_id conditional string发放红包使用场景,红包金额小于 1 元或大于 200 元时必传。具体属性看下方 scene_id 属性值。
scene_id 参数
参数描述
PRODUCT_1 string商品促销
PRODUCT_2 string抽奖
PRODUCT_3 string虚拟物品兑奖
PRODUCT_4 string企业内部福利
PRODUCT_5 string渠道分润
PRODUCT_6 string保险回馈
PRODUCT_7 string彩票派奖
PRODUCT_8 string税务刮奖

返回

同步返回红包支付结果。如果发生错误,则会返回错误码和错误详情,详见 错误

定义

POST https://api.pingxx.com/v1/red_envelopes
\Pingpp\RedEnvelope::create();
RedEnvelope.create();
Pingpp::RedEnvelope.create()
pingpp.redEnvelopes.create();
pingpp.RedEnvelope.create();
redEnvelope, err := redEnvelope.New(&RedenvelopeParams)
create(Dictionary<String, Object> params)

请求示例

curl https://api.pingxx.com/v1/red_envelopes \
-u sk_test_ibbTe5jLGCi5rzfH4OqPW9KC: \
-d order_no=123456789 \
-d app[id]=app_1Gqj58ynP0mHeX1q \
-d channel=wx_pub \
-d amount=100 \
-d currency=cny \
-d subject="Your Subject" \
-d body="Your Body" \
-d extra[send_name]="Send Name" \
-d recipient=Openid \
-d description="Your Description"
\Pingpp\Pingpp::setApiKey('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');

\Pingpp\RedEnvelope::create(
    array(
        'subject'     => 'Your Subject',
        'body'        => 'Your Body',
        'amount'      => 100,
        'order_no'    => '123456789',
        'currency'    => 'cny',
        'extra'       => array(
            'send_name' =>; 'Send Name'
        ),
        'recipient'   => 'Openid',
        'channel'     => 'wx_pub',
        'app'         => array('id' => 'app_1Gqj58ynP0mHeX1q'),
        'description' => 'Your Description'
    )
);
Pingpp.apiKey = "sk_test_ibbTe5jLGCi5rzfH4OqPW9KC";

Map<String, Object> redenvelope = new HashMap<String, Object>();
redenvelope.put("amount", 100);
redenvelope.put("currency", "cny");
redenvelope.put("subject",  "Your Subject");
redenvelope.put("body",  "Your Body");
redenvelope.put("order_no",  "123456789");
redenvelope.put("channel",  "wx_pub");
redenvelope.put("recipient", "Openid");
redenvelope.put("description", "Your Description");
Map<String, String> app = new HashMap<String, String>();
app.put("id", "app_1Gqj58ynP0mHeX1q");
redenvelope.put("app", app);
Map<String, String> extra = new HashMap<String, String>();
extra.put("send_name", "Send Name");
redenvelope.put("extra", extra);
RedEnvelope red = RedEnvelope.create(redenvelope);
System.out.println(red);
require "pingpp"
require "digest/md5"

Pingpp.api_key = "sk_test_ibbTe5jLGCi5rzfH4OqPW9KC"
red = Pingpp::RedEnvelope.create(
  :order_no    => "123456789",
  :app         => { :id => "app_1Gqj58ynP0mHeX1q" },
  :channel     => "wx_pub",
  :amount      => 100,
  :currency    => "cny",
  :subject     => "Your Subject",
  :body        => "Your Body",
  :extra       => {
    :send_name => "Send Name"
  },
  :recipient   => "Openid",
  :description => "Your Description"
)
var pingpp = require('pingpp')('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');

pingpp.redEnvelopes.create({
  order_no:    "123456789",
  app:         { id: "app_1Gqj58ynP0mHeX1q" },
  channel:     "wx_pub",
  amount:      100,
  currency:    "cny",
  subject:     "Your Subject",
  body:        "Your Body",
  extra: {
    send_name: "Send Name"
  },
  recipient:   "Openid",
  description: "Your Description"
}, function(err, redEnvelope) {
  // YOUR CODE
});
pingpp.api_key = 'sk_test_ibbTe5jLGCi5rzfH4OqPW9KC'

redenvelope = pingpp.RedEnvelope.create(
    order_no='123456789',
    channel='wx_pub',
    amount=100,
    subject='Your Subject',
    body='Your Body',
    currency='cny',
    app=dict(id='app_1Gqj58ynP0mHeX1q'),
    extra=dict(send_name='Send Name'),
    recipient='Openid',
    description='Your Description'
)
extra := make(map[string]interface{})
extra["send_name"] = "Send Name"

redenvelopeParams := &pingpp.RedEnvelopeParams{
    App:         &pingpp.App{Id: "app_1Gqj58ynP0mHeX1q"},
    Channel:     "wx_pub",
    Order_no:    "123456789",
    Amount:      100,
    Currency:    "cny",
    Recipient:   "Openid",//指定用户的 open_id
    Subject:     "Your Subject",
    Body:        "Your Body",
    Description: "Your Description",
    Extra:       extra,
  }
redEnvelope, err := redEnvelope.New(redenvelopeParams)
    Dictionary<String, String> app = new Dictionary<String, String>();
    app.Add("id", "app_1Gqj58ynP0mHeX1q");
    Dictionary<String, String> extra = new Dictionary<String, String>();
    extra.Add("Nick Name");
    extra.Add("send_name", "Send Name");
    Dictionary<String, Object> params = new Dictionary<String, Object>();
    params.Add("amount", 100);
    params.Add("currency", "cny");
    params.Add("subject",  "Your Subject");
    params.Add("body",  "Your Body");
    params.Add("order_no",  "123456789");
    params.Add("channel",  "wx_pub");
    params.Add("recipient", "Your Openid");
    params.Add("description", "Your Description");
    params.Add("app", app);
    params.Add("extra", extra);
    try {
        RedEnvelope red = RedEnvelope.create(params);
        Console.WriteLine(red);
    } catch (Exception e) {
        Console.WriteLine(e.Message.ToString());
    }

返回示例

{
  "id": "red_KCabLO58W5G0rX90iT0az5a9",
  "object": "red_envelope",
  "created": 1428499439,
  "received": null,
  "refunded": null,
  "livemode": true,
  "status": "sending",
  "app": "app_1Gqj58ynP0mHeX1q",
  "channel": "wx_pub",
  "order_no": "123456789",
  "transaction_no": null,
  "amount": 100,
  "amount_settle": 100,
  "currency": "cny",
  "recipient": "Openid",
  "subject": "Your Subject",
  "body": "Your Body",
  "description": "Your Description",
  "failure_msg":null,
  "extra": {
    "send_name": "Send Name"
  }
}